package xing.design.pattern.behavioral.Memento.sample3_andCommandPattern.editor.command.edit;

import xing.design.pattern.behavioral.Memento.sample3_andCommandPattern.editor.Editor;

/**
 * @author xing
 * @date 2023/2/10 15:17:54
 */
public class RemoveCommand extends EditCommand {
    private int removeSize = 0;

    public RemoveCommand(int removeSize) {
        this.removeSize = removeSize;
    }

    @Override
    protected void doExecute(Editor editor) {
        String content = editor.getContent();
        String substring = content.substring(0, content.length() - 1 - removeSize);
        editor.setContent(substring);
    }

    @Override
    public String getName() {
        return "remove";
    }
}
